package com.example.boot.controller;

import com.example.common.LngLat;
import com.example.common.LogAnno;
import com.example.common.Result;
import com.example.common.enums.LogType;
import com.example.pojo.dto.MarkerDTO;
import com.example.pojo.entity.Marker;
import com.example.pojo.vo.MarkerVO;
import com.example.service.MarkerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author ding
 * @since 2024/5/31
 */
@RestController
@RequestMapping("/marker")
@Slf4j
@Api(tags = "标点相关接口")
public class MarkerController {

    @Autowired
    private MarkerService markerService;

    /**
     * 新增地图标点
     */
    @LogAnno(title = "标点管理", type = LogType.ADD)
//    @PreAuthorize("hasAuthority('MARKER_ADD')")
    @PostMapping("/add")
    public Result add(@RequestBody Marker marker){
        markerService.add(marker);
        return Result.success();
    }

    /**
     * 根据当前登录用户id，获得其团队所负责项目的全部地图标点
     */
//    @PreAuthorize("hasAuthority('MARKER_QUERY')")
    @GetMapping("/selectAll/{userId}")
    public Result getAll(@PathVariable Integer userId){

        List<Marker> markerList = markerService.getAll(userId);
        return Result.success(markerList);
    }

    /**
     * 删除地图坐标点
     */
    @LogAnno(title = "坐标管理", type = LogType.DELETE)
//    @PreAuthorize("hasAuthority('MARKER_DELETE')")
    @DeleteMapping("/delete/{projectId}")
    public Result deleteByLngLat(@PathVariable Integer projectId){
        markerService.deleteByLngLat(Integer.valueOf(projectId));
        return Result.success();
    }

//    @PreAuthorize("hasAuthority('MARKER_QUERY')")
    @GetMapping("/getByProjectId/{projectId}")
    public Result getByProjectId(@PathVariable Integer projectId){
        log.info("根据项目id获取对应坐标点:{}",projectId);
        Marker marker = markerService.getByProjectId(projectId);
        return Result.success(marker);
    }

//    @PreAuthorize("hasAuthority('MARKER_QUERY')")
    @GetMapping("/allMarker")
    public Result getEChartData() {
        List<MarkerVO> markerVOList = markerService.getEChartData();
        return Result.success(markerVOList);
    }

    @ApiOperation("根据标点获取该标点处所处具体地址")
    @PostMapping("/getAddress")
    public Result getAddressByLngLat(@RequestBody MarkerDTO markerDTO) {
        String address = markerService.getAddressByLngLat(markerDTO);
        return Result.success(address);
    }
}
